// pages/state_page/index.js
import { qualificateList, qualificateDetail, qualificateApply, qualificateData } from '../../api/qualificate.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state: -1,//认证状态：1=认证成功；2=认证失败；3=认证中
    pid:'',
    applyId:'',
    qualificateId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._qualificateData(options.pid)
    if (options.status){
      this.setData({ state: options.status})
    }
    this.setData({ pid: options.pid})
  },

  //获取状态
  _qualificateData(id=this.data.pid) {
    qualificateData(id).then(res => {
      if (res.data != '' && res.data != null) {
        this.setData({ state: res.data.status, applyId: res.data.applyId, qualificateId: res.data.qualificateId})
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  goto(){
    if (this.data.state == 3) {//认证中 刷新
      this._qualificateData()
    } else{ // 认证成功/失败 重新认证
      wx.navigateBack({ applyId: this.data.applyId})
      wx.navigateTo({
        url: `/pages/input_information/index?stop=true&qualificateId=${this.data.qualificateId}&pid=${this.data.pid}&applyId=${this.data.applyId}`,
      })
    }
  },
  comeBreak(){
   wx.navigateBack({
    delta: 2
   })
  }
})